#include<bits/stdc++.h>
using namespace std;
#define int long long

int n;
string s[25];
int vis[25];

int check(string a, string b) {
	string t = "";
	int return_index = -1;

	for (int i = a.size() - 1; i >= 0; i--) {
		t = a[i] + t;

		int index = b.find(t);
		if (index == -1 && return_index == -1)
			return -1;
		else if (index == -1)
			break;
		else if (index == 0)
			return_index = t.size();
	}
cout << return_index << endl;
	// 警钟长鸣！！！
	if (a.size() == 1)
		return return_index;
	if (return_index == a.size() || return_index == b.size())
		return -1;
	return return_index;
}

int ans;

void dfs(string loong) {
	cout << loong << endl;
	for (int i = 1; i <= n; i++) {
		if (vis[i] == 2)	continue;

		int index = check(loong, s[i]);
		if (index != -1) {
			vis[i]++;
			dfs(loong + s[i].substr(index));
			vis[i]--;
		}
	}
	if (ans < loong.size())
		ans = loong.size();

}

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> s[i];

	string loong;
	cin >> loong;
	dfs(loong);
	cout << ans;
	return 0;
}
